Skip to content

Conversation

@eduardomb-aw
Copy link
Contributor

  • implemented OAuth token handling with scope support for Entra ID.
  • implemented On-Behalf-Of flow for secure downstream API calls (Microsoft Graph, and SharePoint).
  • Updated README.md for setup, usage, and troubleshooting.

I updated the ClientOAuthProvider to be compatible with MS Entra and added sample projects for that scenario.

PS: This will fix issue 939.

Motivation and Context

It is very important for the SDK to work with MS Entra for authentication and authorization.

How Has This Been Tested?

I tested with my MS Entra tenant. The sample project works and is able to successfully authenticate, exchange the token, and call downstream apis (MS Graph and SharePoint) accordingly.

Breaking Changes

Don't think so.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

- implemented OAuth token handling with `scope` support for Entra ID.
- implemented On-Behalf-Of flow for secure downstream API calls (Microsoft Graph, and SharePoint).
- Updated `README.md` for setup, usage, and troubleshooting.
@eduardomb-aw eduardomb-aw marked this pull request as draft November 4, 2025 21:57
["resource"] = resourceUri.ToString(),
});
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PederHP , the code below behaves as I intended, but it's not a good implementation. The issue here is that if I pass the resource to Entra as it's defined in the PRM (e.g.: http://localhost:7071/) it will never be validated by it and all token requests result in a BadRequest that in PS looks like this:

image

At the same time, if I update the configuration to the expected value (the server app registration client id), it's not validated by the provider:

image

I tried to find alternatives, but am also trying to keep changes to a minimum. Would appreciate if you could share your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had previous PR's (#617 (comment)) to add an Entra-based sample, but we haven't merged them, because Entra doesn't implement all the security features required by the MCP spec yet. Namely, Entra doesn't properly handle this "resource" parameter (RFC 8707) as required by the MCP spec.

MCP clients MUST include the resource parameter in authorization and token requests as specified in the Resource Parameter Implementation section

https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization#token-audience-binding-and-validation

@localden explains why this requirement is important for security in https://den.dev/blog/mcp-authorization-resource/, so I don't think it's a good idea to violate the MCP spec here.

Copy link
Contributor

@halter73 halter73 Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@localden did request that we remove the MUST requirement for the client sending in modelcontextprotocol/modelcontextprotocol#1614, but I don't think we should merge this ahead of the actual protocol change assuming it happens.

And even if the resource parameter isn't required, I think we should at least try to send the resource parameter first, since it can certainly enhance security. And then after that we should fall back to using a scope as suggested in modelcontextprotocol/modelcontextprotocol#1614. If the AS cannot support either, the client should fail to authenticate as it does today.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was typing the below as I noticed your second comment above. Both you points make sense. Agree that this shouldn't be merged.

Do you need me to do anything here or just leave it? Also, any ETA on an updated package for the SDK? (there are some updates not included in the last release that it would be great to have).


My interpretation about the specifications:

So, RFC 8707 states that:

"In requests to the authorization server, a client MAY indicate the protected resource (a.k.a. resource server, application, API, etc.) to which it is requesting access by including the following parameter in the request."

and the MCP specification states that:

"MCP clients MUST implement Resource Indicators for OAuth 2.0 as defined in RFC 8707"

But in reality the interpretation is that the MCP specification says it has to be more restrictive than the RFC? I'm confused. Would that be NOT following the RFC.

PS: My personal preference would be to be more restrictive, I'm just skeptical of that becoming true for Entra any time soon (if at all). This would be a huge blocker for many, I believe.

RFC 8707 - Resource Parameter
MCP - Resource Parameter Implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientOAuthProvider does not work with MS Entra

2 participants